//
//  Message.swift
//  
//
//  Created by 孙长坦 on 2023/3/22.
//

import Foundation

public struct Message {
    init?(values: [AnyHashable: Any]) {
        if let id = values["id"] as? String,
           let type = values["type"] as? String,
           let title = values["title"] as? String,
           let desc = values["desc"] as? String,
           let content = values["content"] as? [String: Any],
           let timestamp = values["timestamp"] as? Int64 {
            self.init(id: id, title: title, desc: desc, type: type,
                      content: content,
                      timestamp: Date(timeIntervalSince1970: Double(timestamp) / 1000))
            return
        }
        
        return nil
    }
    
    init(id: String, title: String, desc: String, type: String,
         content: [String: Any], timestamp: Date) {
        self.id = id
        self.type = type
        self.title = title
        self.desc = desc
        self.content = content
        self.timestamp = timestamp
    }
    
    public let id: String
    
    public let type: String
    
    public let title: String
    
    public let desc: String
    
    public let content: [String: Any]
    
    public let timestamp: Date
}
